package com.css.dzj.dzjdzqs.modules.apaction.apother.service.impl;

import com.alibaba.fastjson.JSON;
import com.css.dzj.dzjdzqs.common.util.HttpClientUtil;
import com.css.dzj.dzjdzqs.modules.apaction.apother.Vo.ApOtherVo;
import com.css.dzj.dzjdzqs.modules.apaction.apother.entity.ApOtherEntity;
import com.css.dzj.dzjdzqs.modules.apaction.apother.mapper.ApOtherMapper;
import com.css.dzj.dzjdzqs.modules.apaction.apother.service.ApOtherService;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author WT
 * @Date 2020/6/28
 */
@Service
public class ApOtherServiceImpl implements ApOtherService {

    @Autowired
    JPAQueryFactory jpaQueryFactory;
    @Autowired
    private ApOtherMapper apOtherMapper;
    @Value("${AP_URL}")
    private String apUrl;

    @Override
    @Transactional
    public void add(List<ApOtherVo> apOtherVoList) {

        try {
            for(ApOtherVo apOtherVo :apOtherVoList){
                ApOtherEntity apOtherEntity = new ApOtherEntity();
                apOtherEntity.setActionId(apOtherVo.getActionId());
                apOtherEntity.setRecordUniqueIdentity(apOtherVo.getRecordUniqueIdentity());
                apOtherEntity.setSuperviseItemCode(apOtherVo.getSuperviseItemCode());
                apOtherEntity.setActionName(apOtherVo.getActionName());
                apOtherEntity.setActionCode(apOtherVo.getActionCode());
                apOtherEntity.setCheckBehaviorNumber(apOtherVo.getCheckBehaviorNumber());
                apOtherEntity.setSuperviseObject(apOtherVo.getSuperviseObject());
                apOtherEntity.setItemSource(apOtherVo.getItemSource());
                apOtherEntity.setImplementInstitution(apOtherVo.getImplementInstitutio());
                apOtherEntity.setImplementInstitutionCode(apOtherVo.getImplementInstitutioCode());
                apOtherEntity.setEntrustDept(apOtherVo.getEntrustDept());
                apOtherEntity.setEntrustDeptCode(apOtherVo.getEntrustDeptCode());
                apOtherEntity.setAdministrativeCp(apOtherVo.getAdministrativeCp());
                apOtherEntity.setAdministrativeCpNa(apOtherVo.getAdministrativeCpNa());
                apOtherEntity.setAdministrativeCpCeType(apOtherVo.getAdministrativeCpCeType());
                apOtherEntity.setAdministrativeCpUiCode(apOtherVo.getAdministrativeCpUiCode());
                apOtherEntity.setAddressRegistered(apOtherVo.getAddressRegistered());
                apOtherEntity.setAddressOperating(apOtherVo.getAddressOperating());
                apOtherEntity.setAreaNumber(apOtherVo.getAreaNumber());
                apOtherEntity.setSuperviseMeasure(apOtherVo.getSuperviseMeasure());
                apOtherEntity.setClosingCase(apOtherVo.getClosingCase());
                apOtherEntity.setStartDate(apOtherVo.getStartDate());
                apOtherEntity.setEndDate(apOtherVo.getEndDate());
                apOtherEntity.setSubmittedDate(apOtherVo.getSubmittedDate());
                apOtherEntity.setSubmittedPersonnel(apOtherVo.getSubmittedPersonnel());
                apOtherMapper.save(apOtherEntity);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    @Transactional
    public void pushtOther() {

        try{
            String msg = HttpClientUtil.doGet(apUrl+"/other/getApList");
            List<ApOtherVo> apOtherVoList = JSON.parseArray(msg, ApOtherVo.class);
            if(null!=apOtherVoList && apOtherVoList.size()>0){
                add(apOtherVoList);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
